home *** CD-ROM | disk | FTP | other *** search
- Subject: Re: Creating a resource from a stream
- Sent: 9/4/96 12:15 PM
- Received: 9/4/96 12:15 PM
- From: motion@nbn.com (Arni McKinley)
- Reply-To: ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List
-
-
- >I have implemented a Save As dialog similar to that of Cyberdog, and can
- >now output TEXT files. Now I would like to output stylized text files. Is
- >there a way to create a 'styl' resource from a stream?
- >
- >Ken Boyer
- >Digital Harbor
-
- ____________
-
- Hi Ken,
-
- To stream styled text, write out the text first as a FW_CString, then call
- GetTEScrap() below using the TEHandle. This returns a handle to a
- StScrpHandle. Write this handle to the stream. Here are some tuilities:
-
- //--------------------------------------------------------------------------
- --------------
- // ::GetTEScrap
- //
- // Get the style info of a TERec (called the "scrap"). This is
- a copy
- //--------------------------------------------------------------------------
- --------------
- StScrpHandle GetTEScrap( TEHandle macTEHndl )
- {
- if( macTEHndl == NULL )
- return NULL;
-
- // Select all of the text first
- short oldStart = (**macTEHndl).selStart;
- (**macTEHndl).selStart = 0;
- short oldEnd = (**macTEHndl).selEnd;
- (**macTEHndl).selEnd = 32767;
-
- // Get the StScrpHandle
- StScrpHandle hStScrap = ::TEGetStyleScrapHandle( macTEHndl );
-
- // Reset the old selection points
- (**macTEHndl).selStart = oldStart;
- (**macTEHndl).selEnd = oldEnd;
-
- return hStScrap;
- }
-
-
- //--------------------------------------------------------------------------
- --------------
- // ::SetTEScrap
- //
- // Set the style info of a TERec (called the "scrap") into the
- given TERec
- //--------------------------------------------------------------------------
- --------------
- void SetTEScrap( FW_CString& text, StScrpHandle hStHndl, TEHandle macTEHndl )
- {
- if( macTEHndl == NULL )
- return;
-
- ::TEStyleInsert( text.RevealBuffer(), text.GetByteLength(),
- hStHndl, macTEHndl );
- }
-
- //--------------------------------------------------------------------------
- --------------
- // ::WriteTEScrapDirect
- //
- // Write the style info of a TERec (called the "scrap") to the
- given archive
- //--------------------------------------------------------------------------
- --------------
- void WriteTEScrapDirect( FW_CWritableStream& archive, StScrpHandle hStScrap )
- {
- FW_ASSERT( hStScrap != NULL );
-
- archive << (FW_Boolean) TRUE; // The record exists
-
- // Save the size of the scrap so we can read it back in
- unsigned long scrapLen = FW_CMemoryManager::GetSystemHandleSize(
- (FW_PlatformHandle) hStScrap );
- archive << scrapLen;
-
- FW_CAcquireLockedSystemHandle locked (( FW_PlatformHandle) hStScrap );
- archive.Write( locked.GetPointer(), scrapLen );
-
- // Don't delete!!
- }
-
- //--------------------------------------------------------------------------
- --------------
- // ::WriteTEScrap
- //
- // Write the style info of a TERec (called the "scrap") to the
- given archive
- //--------------------------------------------------------------------------
- --------------
- void WriteTEScrap( FW_CWritableStream& archive, TEHandle macTEHndl )
- {
- FW_ASSERT( macTEHndl != NULL );
-
- // Get the STScrpHandle
- StScrpHandle hStScrap = ::GetTEScrap( macTEHndl );
- // Now save the StScrpRec
- if( hStScrap == NULL )
- archive << (FW_Boolean) FALSE;
- else
- {
- archive << (FW_Boolean) TRUE; // The record exists
-
- // Save the size of the scrap so we can read it back in
- unsigned long scrapLen =
- FW_CMemoryManager::GetSystemHandleSize( (FW_PlatformHandle) hStScrap );
- archive << scrapLen;
-
- FW_CAcquireLockedSystemHandle locked (( FW_PlatformHandle)
- hStScrap );
- archive.Write( locked.GetPointer(), scrapLen );
-
- // Cleanup
- FW_CMemoryManager::FreeSystemHandle( (FW_PlatformHandle)
- hStScrap );
- }
- }
-
- //--------------------------------------------------------------------------
- --------------
- // ::ReadTEScrap
- //
- // Read the style info of a TERec (called the "scrap") from
- the given archive
- //--------------------------------------------------------------------------
- --------------
- StScrpHandle ReadTEScrap( FW_CReadableStream& archive )
- {
- FW_Boolean recordExists;
- archive >> recordExists;
- if( recordExists == FALSE )
- return NULL;
-
- // Get the length of the scrap handle
- unsigned long scrapLen;
- archive >> scrapLen;
-
- StScrpHandle hStScrap = (StScrpHandle)
- FW_CMemoryManager::AllocateSystemHandle( scrapLen );
- FW_ASSERT( hStScrap );
- FW_TRY
- {
- FW_CAcquireLockedSystemHandle locked (( FW_PlatformHandle)
- hStScrap );
- archive.Read( locked.GetPointer(), scrapLen );
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING ()
- {
- FW_CMemoryManager::FreeSystemHandle( (FW_PlatformHandle)
- hStScrap );
- FW_THROW_SAME ();
- }
- FW_CATCH_END
-
- return hStScrap;
- }
-
- Arni F. McKinley
- President
- MetaMind Software, Inc.
- Mill Valley, CA 94941
- motion@nbn.com
- www.nbn.com/people/minds
- _______________________________________